package spotGUI.utils;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class ImageBackgroundPanel extends JPanel implements ComponentListener{
	/**
	 * Create the panel.
	 */
	private Image img;
	private URL imagePath;


	public ImageBackgroundPanel(String imageName, int width, int height) {
		setOpaque(false);
		setLayout(new BorderLayout(0, 0));
		imagePath = ImageBackgroundPanel.class.getResource("/images/GUIBackgrounds/"+imageName);
		setSize(new Dimension(width, height));
	}

	public void paintComponent(Graphics g) {
		g.drawImage(img, 0, 0, this);
		super.paintComponent(g);
	}

	@Override
	public void setSize(int width, int height) {
		super.setSize(width, height);
		img = new ImageIcon(imagePath).getImage();
		img = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
	}

	@Override
	public void componentHidden(ComponentEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void componentMoved(ComponentEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void componentResized(ComponentEvent arg0) {
		Dimension d = ((Component)arg0.getSource()).getSize();
		setSize(d.width, d.height);

	}

	@Override
	public void componentShown(ComponentEvent arg0) {
		// TODO Auto-generated method stub

	}
}
